package com.boot.demo.controller;

import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {
    @GetMapping("/login/{id}/{name}")
    public void login(HttpServletRequest request, @PathVariable Integer id, @PathVariable String name){
        JSONObject user = new JSONObject();
        user.put("id",id);
        user.put("name",name);
        request.getSession().setAttribute("user",user.toString());
    }

    @GetMapping("/main")
    public String hello(HttpServletRequest request){
        String sessionId = request.getSession().getId();
        String user = (String) request.getSession().getAttribute("user");
        return "这是222222222222222</br>" + "sessionId : " + sessionId + "</br>user : " + user;
    }
}
